<%--
   insecptCi
   Copyright (c) 2015 ISPERP
   Version : 1.0.0
 --%> 
<%@tag import="org.apache.commons.lang3.StringUtils"%>
<%@tag import="itsm.isperp.module.service.task.TskInspectCiCheckService"%>
<%@tag
	import="itsm.isperp.module.service.task.TskInspectCiCateCheckService"%>
<%@tag import="itsm.isperp.module.entity.task.TskInspectCiCateCheck"%>
<%@tag import="java.util.Map"%>
<%@tag import="java.util.List"%>
<%@tag import="itsm.isperp.module.service.task.TskInspectCiInfoService"%>
<%@tag import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@ tag language="java" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>


<%@ attribute name="id" required="true" type="java.lang.String"
	description="id"%>
<%@ attribute name="relationId" required="true" type="java.lang.String"
	description="relationId"%>

<%@ attribute name="readonly" required="false" type="java.lang.Boolean"
	description="readonly"%>

<%
	TskInspectCiInfoService tskInspectCiInfoService = ContextHolder
			.getSpringBean("tskInspectCiInfoService");

	TskInspectCiCateCheckService tskInspectCiCateCheckService = ContextHolder
			.getSpringBean("tskInspectCiCateCheckService");

	TskInspectCiCheckService tskInspectCiCheckService = ContextHolder
			.getSpringBean("tskInspectCiCheckService");

	List<Map<String, Object>> list = tskInspectCiInfoService
			.findByTaskId(relationId);

	for (Map<String, Object> map : list) {

		String conf_category_id = (String) map.get("conf_category_id");
		String ciId = (String) map.get("ci_id");
		List<Map<String, Object>> checks = tskInspectCiCheckService
				.findByTaskIdAndCiId(relationId, ciId);
%>
<h3>
	<a href="javascript:void()"
		onclick="isperp.openDialog({contentUrl:'configuration/ci/edit?id=<%=ciId%>'})"
		class="nui-txt-link"> <%
 	out.print(map.get("name"));
 %> </a>
</h3>

<%
	out.print("<table class='form-table'>");
		for (Map<String, Object> cMap : checks) {

			String default_vlaue = cMap.get("default_vlaue") == null ? ""
					: (String) cMap.get("default_vlaue");
			String check_value = (String) cMap.get("check_value");
			String check_unit = (String) cMap.get("check_unit");

			String data_type = (String) cMap.get("data_type");
			String cate_check_id = (String) cMap.get("cate_check_id");
			String ci_id = (String) cMap.get("ci_id");
			String remark_value = (String) cMap.get("remark");

			Object need_remark = cMap.get("need_remark");

			out.print("<tr><td class='td1'>");

			out.print(cMap.get("check_name") + "：");

			out.print("</td><td class='td2' ><input type='hidden' name='ciCheckInfoId' value='"
					+ (String) cMap.get("id") + "'>");
			out.print("<input type='hidden' name='cateCheckId' value='"
					+ cate_check_id + "'>");
			out.print("<input type='hidden' name='ciCheckCiId' value='"
					+ ci_id + "'>");

			if (readonly != null && readonly == true) {
				out.print(check_value == null ? "" : check_value);
				out.print(check_unit == null ? "" : check_unit);
				if (StringUtils.isNotEmpty(remark_value))
					out.print("（" + remark_value + "）");
			} else {
				if ("select".equals(data_type)) {
					String itemStr = (String) cMap.get("items");
					out.print("<select  name='ciCheckValue' >");
					String[] items = itemStr.split("\\|");
					for (int ii = 0; ii < items.length; ii++) {
						out.print("<option >");

						out.print(items[ii]);

						out.print("</option >");
					}

					out.print("</select>");
				} else {
					out.print("<input name='ciCheckValue' type='text' class='ci_check_value "
							+ data_type
							+ "' value='"
							+ (check_value == null ? "" : check_value)
							+ "'>");

					out.print(check_unit == null ? "" : check_unit);
				}

				if (need_remark != null
						&& ((Boolean) need_remark) == true) {
					out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
					out.print("（<input name='ciCheckRemark' class='ci_check_remark' type='text' style='border-top:none;border-right:none;border-left:none' value='"
							+ (remark_value == null ? "" : remark_value)
							+ "'>）");
				} else {
					out.print("<input type='hidden' name='ciCheckRemark' class='ci_check_remark' >");

				}
			}

			out.print("</td></tr>");

		}
		out.print("</table>");
	}
%>

